<extend name="./Application/Admin/View/Public/base.html" />
<block name="eosi-css">
    <link href="__PUBLIC__/assets/css/daterangepicker.css" rel="stylesheet">
    <link href="__PUBLIC__/assets/css/iconfont.css" rel="stylesheet">
    <link href="__PUBLIC__/assets/css/fileUpload.css" rel="stylesheet">
    <link href="__PUBLIC__/assets/css/rili.css" rel="stylesheet">
</block>
<block name="eosi-js"> 
    <script src="__PUBLIC__/assets/js/date-time/bootstrap-datepicker.min.js"></script>
    <script src="__PUBLIC__/assets/js/jqGrid/jquery.jqGrid.min.js"></script>
     <script src="__PUBLIC__/assets/js/jqGrid/laydate.dev.js"></script>
    <script type="text/javascript">
        var $path_base = "/";//this will be used in gritter alerts containing images
    </script>

</block>
<block name="page-content">
    <div class="row">
        <div class="col-xs-12">
            <div class="row-fluid">
                <div class="span12">
                    <div class="widget-box">
                        <div class="widget-header header-color-blue">
                            <h5 class="lighter">
                                编辑造型
                            </h5>
                        </div>
                        <div class="widget-body">
                            <div class="widget-main no-padding">
                                <form class="form-horizontal"  name="saveForm" id="saveForm"  method="post"  action="{:U('updateRule')}" encType="multipart/form-data">
                                    <input type="hidden" name="id" id="id" value="{$data.id}">
                                    <table class="table table-striped table-bordered table-hover">
                                        <tbody>
                                            <!-- <tr>
                                                <td class="no-padding-right" width="15%">
                                                    <label class="control-label"><small>用户</small></label>
                                                </td>
                                                <td>
                                                    <input type="text" id="uid" name="uid" value="{$data.uid}" class="col-xs-10 col-sm-4" />
                                                </td>
                                            </tr> -->
                                            <tr>
                                                <td class="no-padding-right" width="15%">
                                                    <label class="control-label"><small>造型类型<span class="red">*</span></small></label>
                                                </td>
                                                <td>
                                                    <select  id="cate" name="cate" disabled="disabled" >
                                                        <option  <if condition="$data.cate == 1"  
                                                            > selected </if> value="1">用户自编造型</option>
                                                        <option <if condition="$data.cate == 2"  
                                                            > selected </if>  value="2">百家好推荐造型</option>
                                                    </select>
                                                    <!-- <input type="hidden" id="cate" name="cate" value="{$data.cate}" class="col-xs-10 col-sm-4" /> -->
                                                    <!-- <volist name="_listopt" id="opt"> 
                                                            <option <if condition="$data.cate == $opt['id']"  
                                                            > selected </if> value ="{$opt.id}"  >{$opt.name}</option>
                                                    </volist> -->
                                                </td>
                                            </tr>

                                            <tr>
                                                <td class="no-padding-right" width="15%">
                                                    <label class="control-label"><small>类别<span class="red">*</span></small></label>
                                                </td>
                                                <td>
                                                    <select  id="test"  name="type"> 
                                                        <volist name="_listopt" id="opt"> 
                                                            <option <if condition="$data.label == $opt['id']"  
                                                            > selected </if> value ="{$opt.id}"  >{$opt.name}</option>
                                                        </volist>
                                                    </select>
                                                </td>
                                            </tr>

                                            <tr>
                                                <td class="no-padding-right" width="15%">
                                                    <label class="control-label"><small>显示顺序<span class="red">*</span></small></label>
                                                </td>
                                                <td>
                                                    <input type="text" id="show_order" name="show_order" value="{$data.show_order}" class="col-xs-10 col-sm-1" />
                                                    <span class="middle control-label red">&nbsp;&nbsp; 请填入数字，值越大越靠前显示</span>
                                                </td>
                                            </tr>
                                            
                                            <tr>
                                                <td class="no-padding-right" width="15%">
                                                    <label class="control-label"><small>造型主图<span class="red">*</span></small></label>
                                                </td>
                                                <td>
                                                    <!-- <input name="upimage" id="upimage" type="file" class="file huge" style="display: inline-block;"> -->

                                                    <img src='{$data.img}' id="img" name="img" style="width:400px">
                                                    <input type="file" name="p_img" id="p_img">
                                                    <span class="middle control-label red">&nbsp;&nbsp;图片建议尺寸：1200x1400像素</span>
                                                    <input type="hidden" id="p_new_pic" name="p_new_pic" value="{$data.aimg}">
                                                    <iframe style="display: none;" id="upload_img" name="upload_img"></iframe>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="no-padding-right" width="15%">
                                                    <label class="control-label"><small>造型其它副图</small></label>
                                                </td>
                                                <td>
                                                    
                                                    <div id="fileUploadContent" class="fileUploadContent"></div>
                                                    <span class="middle control-label red">&nbsp;&nbsp;图片建议尺寸：1200x1400像素</span>
                                                    <input type="hidden" id="new_img" name="new_img" value="{$datasubstr}">
                                                    
                                                </td>
                                            </tr>
                                            <!-- <tr>
                                                <td class="no-padding-right" width="15%">
                                                    <label class="control-label"><small>本造型组成元素</small></label>
                                                </td>
                                                <td>
                                                    <input type="hidden" id="new_img" name="new_img" />
                                                    <div id="fileUploadContent" class="fileUploadContent"></div>
                                                </td>
                                            </tr> -->
                                            <tr>
                                                <td class="no-padding-right" width="15%">
                                                    <label class="control-label"><small>状态<span class="red">*</span></small></label>
                                                </td>
                                                <td>
                                                    <input type="radio" name="status" value="1" <if condition="$data.status == 1 "> checked </if>>启用
                                                    <input type="radio" name="status" value="0" <if condition="$data.status == 0 "> checked </if>>禁用
                                                    <input type="radio" name="status" value="-1" <if condition="$data.status == -1 "> checked </if>>缺图禁用
                                                </td>
                                            </tr>
                                             <tr>
                                                <td class="no-padding-right" width="15%">
                                                    <label class="control-label"><small>名称</small></label>
                                                </td>
                                                <td>
                                                    <input type="text" id="aname" name="aname" value="{$data.aname}" class="col-xs-10 col-sm-4" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="no-padding-right" width="15%">
                                                    <label class="control-label"><small>附注</small></label>
                                                </td>
                                                <td>
                                                    <input type="text" id="memo" name="memo" value="{$data.memo}" class="col-xs-10 col-sm-4" />
                                                </td>
                                            </tr>

                                            <tr>
                                                <td class="no-padding-right" width="15%">
                                                    <label class="control-label"><small>上衣款号</small></label>
                                                </td>
                                                <td>
                                                    <input type="text" id="sykh" name="sykh" value="{$data.sykh}" class="col-xs-10 col-sm-4" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="no-padding-right" width="15%">
                                                    <label class="control-label"><small>下衣款号</small></label>
                                                </td>
                                                <td>
                                                    <input type="text" id="xykh" name="xykh" value="{$data.xykh}" class="col-xs-10 col-sm-4" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="no-padding-right" width="15%">
                                                    <label class="control-label"><small>配饰款号</small></label>
                                                </td>
                                                <td>
                                                    <input type="text" id="pskh" name="pskh" value="{$data.pskh}" class="col-xs-10 col-sm-4" />
                                                </td>
                                            </tr>
                                           <!--   <tr>
                                                <td class="no-padding-right" width="15%">
                                                    <label class="control-label"><small>编号</small></label>
                                                </td>
                                                <td>
                                                    <input type="text" id="no" name="no" value="{$data.no}" class="col-xs-10 col-sm-4" />
                                                </td>
                                            </tr> -->
                                            <tr>
                                                <td class="no-padding-right" width="15%">
                                                    <label class="control-label"><small>推荐到指定日</small></label>
                                                </td>
                                                <td>
                                                    <input type="text" id="J-xl" name='J-xl'  placeholder="选择日期(非必须)"  value="{$re_date}">
                                                    <br/>
                                                    <span class="middle control-label red">&nbsp;&nbsp;可以选择1个日期作为日历中该日的官方推荐造型</span>
                                                    <!-- <input type="text" id="no" name="no" value="" class="col-xs-10 col-sm-4" /> -->
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>

                                    <table class="table table-striped table-bordered table-hover" id="answer">
                                        <tbody>
                                            <tr>
                                                <td class="no-padding-right" width="15%">

                                                </td>
                                                <td>
                                                    <button class="btn btn-success" type="button" onclick="checkSubmit();">
                                                        <i class="icon-ok bigger-110"></i>
                                                        提交
                                                    </button>
                                                    <button class="btn btn-warning" type="button" onclick="returnButton({});">
                                                        <i class="icon-undo bigger-110"></i>
                                                        返回
                                                    </button>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div><!-- /.row -->
    <script src="__PUBLIC__/assets/js/jqGrid/i18n/fileUpload.js"></script>
    <link href="__PUBLIC__/assets/css/fileUpload.css?v=11" rel="stylesheet">
    <link href="__PUBLIC__/assets/css/iconfont.css" rel="stylesheet">
    <script type="text/javascript">
        laydate({
        elem: '#J-xl'
    }); 
        jQuery(function ($) {
            //提交Form
            checkSubmit = function () {
                var id = $("#id").val();
                if (id == '') {
                    art.dialog.alert("系统缺失主键");
                    return false;
                }
                var aname = $("#aname").val();
                // if (aname == '') {
                //     art.dialog.alert("名称不能为空");
                //     return false;
                // }
                var memo = $("#memo").val();
                // if (memo == '') {
                //     art.dialog.alert("附注不能为空");
                //     return false;
                // }
                var no = $("#no").val();
                if (no == '') {
                    art.dialog.alert("编号不能为空");
                    return false;
                }
                $("#saveForm").attr('action', "{:U('updateRule')}");
                $("#saveForm").attr('target', '_self');
                $("form[name=saveForm]").submit();
            }
            returnButton = function () {
                // location.href = "/Admin/Looks/index";
                history.go(-1);
            }
        });
        $("#p_img").change(function() {
                $("#saveForm").attr('action', "{:U('uploadImg')}");
                $("#saveForm").attr('target', 'upload_img');
                $("#saveForm").submit();
            });
        var opt = {
                    "uploadUrl":"/Admin/Looks/upload",//上传文件信息地址
                    // "progressUrl":"#",//获取进度信息地址，可选，注意需要返回的data格式如下（{bytesRead: 102516060, contentLength: 102516060, items: 1, percent: 100, startTime: 1489223136317, useTime: 2767}）
                    //"showSummerProgress":false,//总进度条，默认限制
                    //"size":350,//文件大小限制，单位kb,默认不限制
                   // "maxFileNumber":3,//文件个数限制，为整数
                    // "filelSavePath":"__PUBLIC__/Uploads/",//文件上传地址，后台设置的根目录
                    "beforeUpload":beforeUploadFun,//在上传前执行的函数
                    "onUpload":onUploadFun,//在上传后执行的函数
                    autoCommit:true,//文件是否自动上传
                    'uploadText':'补充上传(可同时选择多个文件上传)',
                    "onDeleteSingle":onDeleteSingle,
                    //"fileType":['png','jpg','docx','doc']//文件类型限制，默认不限制，注意写的是文件后缀
                }
            $("#fileUploadContent").initUpload(opt)
            function beforeUploadFun(opt){
                     
                 opt.otherData =[{"name":"id","value":$("#id").val()}];
            }

            function onUploadFun(opt,data){
                // console.log(data);
                // console.log(data.info);
                //$("#new_img").val(data.info);
                // uploadTools.uploadError(opt);//显示上传错误
                art.dialog.tips('补充上传成功',2);
                window.location.href=window.location.href;
            }

            function onDeleteSingle(opt,realName){
                    
                    var realNames = $("#new_img").val().split(",");
                    var newNames= new Array();
                    for (var i = 0; i <=realNames.length - 1; i++) {
                        if(realNames[i]!=realName){
                            newNames.push(realNames[i]);
                        }
                        
                    }
                    newNames=newNames.join(',');
                    $("#new_img").val(newNames);
                    var formData = new FormData();
                    formData.append("realName",realName);
                    formData.append("id",$("#id").val());
                    $.ajax({
                        type:"post",
                        url:"/Admin/Looks/uploadDelete",
                        data:formData,
                        processData : false,
                        contentType : false,
                        success:function(data){
                            
                        },
                        error:function(e){

                        }
                    });

                    

                }

            var boxJsObj =  $("#fileUploadContent"+" .box").get(0);
            var fileModel;
            <volist  name= "sub_img_arr" id="voi">                                             
             fileModel = uploadTools.getShowFileType(true,"","{$voi['realName']}",'{$voi["url"]}',0);
            $(boxJsObj).append(fileModel);
            </volist>
            $("#fileUploadContent"+" .fileItem .status i").on("click",function(){
                    uploadEvent.deleteFileEvent(opt,this);
                })
        </script>
</block>